package com.example.rabbitmq4.config;

import com.example.rabbitmq4.constant.Constants;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Bean("confirmQueue")
    public Queue confirmQueue() {
        return QueueBuilder.durable(Constants.CONFIRM_QUEUE).build();
    }

    @Bean("ackQueue")
    public Queue ackQueue() {
        return QueueBuilder.durable(Constants.ACK_QUEUE).build();
    }

    @Bean("noPermanentExchange")
    public TopicExchange noPermanentExchange() {
        return ExchangeBuilder.topicExchange(Constants.NO_PERMANENT_EXCHANGE).durable(false).build();
    }

    @Bean("permanentQueue")
    public Queue permanentQueue() {
        return QueueBuilder.nonDurable(Constants.PERMANENT_QUEUE).build();
    }

    @Bean("permanentExchange")
    public TopicExchange permanentExchange() {
        return ExchangeBuilder.topicExchange(Constants.PERMANENT_EXCHANGE).build();
    }

    @Bean("permanentBinding")
    public Binding permanentBinding(@Qualifier("permanentExchange") Exchange exchange, @Qualifier("permanentQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("permanent").noargs();
    }
}
